/*
 * @Author: your name
 * @Date: 2021-10-01 09:47:10
 * @LastEditTime: 2021-10-06 01:47:56
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \h5\utils\request.js
 */



//请求类
import BASE_API from '../config'
const BASE_URL = BASE_API

export const request = (options) => {

    // let headerlist = {
    //     'Authorization': `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJoZW5nLmxleWljaGluYS50b3AiLCJhdWQiOiJoZW5nLmxleWljaGluYS50b3AiLCJpYXQiOjE2MzM0NTQ0NzMsIm5iZiI6MTYzMzQ1NDQ3MywiZXhwIjoxNjM2MDQ2NDczLCJqdGkiOnsiaWQiOjIwODMsInR5cGUiOiJ3ZWNoYXQifX0.51EmFt4EccfBCv1jtllPaewcbwo2FNUdrgJ43-3Y9y4`
    // };
    return new Promise((resolve, reject) => {
        uni.request({
            url: BASE_URL + options.url, //地址拼接
            method: options.method || 'GET',
            data: options.data,
            // header: headerlist || {},
            success: (res) => {
                resolve(res.data)
            },
            fail: (err) => {
                uni.showToast({
                    title: '获取失败',
                    icon: "none"
                })
                reject(err)
            }
        })
    })
}

//上传类
export const myUploadFile = (options) => {

    let headerlist = {
        'Authorization': `Bearer `
    };
    return new Promise((resolve, reject) => {
        uni.uploadFile({
            url: BASE_URL + options.url,
            files: options.files,
            filePath: options.filePath,
            name: options.name,
            formData: options.formData,
            header: headerlist || {},
            success: (res) => {
                console.log(res)
                if (res.statusCode == 200) {
                    var data = JSON.parse(res.data)
                    resolve(data)
                } else {
                    resolve(res)
                }
            },
            fail: (err) => {
                console.log(err)
                uni.showToast({
                    title: '获取失败',
                    icon: "none"
                })
                reject(err)
            }
        })
    })
}